home *** CD-ROM | disk | FTP | other *** search
/ Aminet 2 / Aminet AMIGA CDROM (1994)(Walnut Creek)[Feb 1994][W.O. 44790-1].iso / Aminet / dev / misc / egs.lha / EGS / EGS_Devels / Examples / EGS_Gadget / gadget1.c < prev    next >
C/C++ Source or Header  |  1993-02-17  |  7KB  |  258 lines

  1. /*
  2. **  CHANGE          : 30 Nov 1992 mvk
  3. **                    17 Dec 1992 mvk
  4. **                    09 Jan 1993 mvk
  5. **
  6. **  This program describes the possibility of scaleable
  7. **
  8. **  gadgets and so on. See important lines at the end of code
  9. **
  10. **  (message handling !).
  11. **
  12. **
  13. **  (C) by VIONA-Development 1991,1993
  14. **
  15. */
  16.  
  17. #include "includes.c"
  18.  
  19. void Crash (char * string);
  20.  
  21. struct Library *EGSIntuiBase;
  22. struct Library *GfxBase;
  23. struct Library *EGBBase;
  24. struct Library *EGBScrollBase;
  25. struct Library *EGBRadioBase;
  26. struct Library *EGBSetBase;
  27. struct Library *EGBSelectBase;
  28. struct Library *EGBTextInfoBase;
  29.  
  30. EI_WindowPtr     window;
  31. EI_EIntuiMsgPtr  msg;
  32. EB_GadContext    con;
  33.  
  34.  
  35. EB_StrArray    Gads1 = { " 8","13","18","24","40",NULL };
  36. EB_StrArray    Gads2 = { "OK","CANCEL",NULL };
  37. EB_StrArray2   Gadgs = { &Gads1, &Gads2, NULL };
  38.  
  39. EI_WindowPtr CreateGads (EI_WindowPtr win)
  40. {
  41.         EB_GadBoxPtr root, help, help2;
  42.         EI_GadgetPtr             tgad;
  43.  
  44.         con = EB_CreateGadContext(NULL,NULL,-1,-1);
  45.  
  46.         if(con == NULL)
  47.            Crash("Cant't create Gadget context !");
  48.  
  49.         root = EB_CreateHorizBox(con);
  50.  
  51.         EB_AddLastSon(root, EB_CreateSuperVertiProp(con, 40, 20, 5, 0x2000,
  52.                                                     EB_DEC_UP_LEFT | EB_INC_BOTTOM_RIGHT ));
  53.  
  54.         EB_AddLastSon(root, EB_CreateHorizFill(con,0,0));
  55.  
  56.         help = EB_CreateVertiBox(con);
  57.  
  58.         EB_AddLastSon(help, EB_CreateVertiFill(con,0,0));
  59.         EB_AddLastSon(help, EB_CreateMultiAction2(con, &Gadgs,0x1000 ));
  60.         EB_AddLastSon(help, EB_CreateVertiFill(con,0,0));
  61.         EB_AddLastSon(help, EB_CreateSuperHorizProp(con, 20, 4, 5, 0x2001,
  62.                                                     EB_DEC_UP_LEFT | EB_INC_BOTTOM_RIGHT ));
  63.  
  64.         EB_AddLastSon(root, help);
  65.  
  66.         EB_AddLastSon(root, EB_CreateHorizFill(con,0,0));
  67.         EB_AddLastSon(root, EB_CreateSuperVertiProp(con, 20, 4, 5, 0x2002,
  68.                                                     EB_DEC_UP_LEFT | EB_INC_BOTTOM_RIGHT ));
  69.  
  70.         EB_AddLastSon(root, EB_CreateHorizFill(con,0,0));
  71.         EB_AddLastSon(root, EGB_CreateLateScrollBox(con,20,40,10,20,1,0x3000));
  72.         EB_AddLastSon(root, EB_CreateHorizFill(con,0,0));
  73.  
  74.         help = EB_CreateHorizBox(con);
  75.  
  76.         EB_AddLastSon(help, EGB_CreateRadioGadget(con,&Gads1,100,0x4000));
  77.         EB_AddLastSon(help, EB_CreateHorizFill(con,0,0));
  78.         EB_AddLastSon(help, EGB_CreateSetGadget(con,&Gads1,100,0x4001));
  79.  
  80.         help2 = EB_CreateVertiBox(con);
  81.  
  82.         EB_AddLastSon(help2, help);
  83.         EB_AddLastSon(help2, EB_CreateVertiFill(con,0,0));
  84.         EB_AddLastSon(help2, EGB_CreateTextSelectGadget(con, 0x5000, &Gads1));
  85.         EB_AddLastSon(root,help2);
  86.  
  87.         root = EB_CreateMasterWindow(con,win,root);
  88.  
  89.        if (EB_ProcessGadBoxes(con,root))
  90.         {
  91.           tgad = EB_FindGadget(con->First, con->Num, 0x6000);
  92.  
  93.           /*
  94.           **  Filling in the EI_NewWindow structure
  95.           */
  96.  
  97.           if (win == NULL)
  98.           {
  99.                                   /* give more flags to the window */
  100.  
  101.           con->NewWin->IDCMPFlags         = EI_iCLOSEWINDOW |
  102.                                             EI_iNEWSIZE     |
  103.                                             EI_iSIZEVERIFY  |
  104.                                             EI_iGADGETUP;
  105.  
  106.           con->NewWin->Bordef.SysGadgets |= (EI_WINDOWCLOSE | EI_WINDOWSIZE);
  107.  
  108.           con->NewWin->MaxWidth           = 800;
  109.           con->NewWin->MaxHeight          = 600;
  110.           con->NewWin->Flags             |= (EI_SIZEBRIGHT);
  111.  
  112.           return (EI_WindowPtr)EI_OpenWindow(con->NewWin);
  113.  
  114.           }else
  115.               return win;
  116.  
  117.         }else
  118.               return NULL;
  119.  
  120. }
  121.  
  122. void Crash (char * string)
  123. {
  124.  
  125.         if (NULL != window)
  126.           EI_CloseWindow( window );
  127.  
  128.         if (NULL != con)
  129.            EB_DeleteGadContext(con);
  130.  
  131.         if (NULL != EGSIntuiBase)
  132.           CloseLibrary( EGSIntuiBase );
  133.  
  134.         if (NULL != EGBBase)
  135.           CloseLibrary( EGBBase );
  136.  
  137.         if (NULL != EGBScrollBase)
  138.           CloseLibrary( EGBScrollBase );
  139.  
  140.         if (NULL != EGBRadioBase)
  141.           CloseLibrary( EGBRadioBase );
  142.  
  143.         if (NULL != EGBSelectBase)
  144.           CloseLibrary( EGBSelectBase );
  145.  
  146.         if (NULL != EGBTextInfoBase)
  147.           CloseLibrary( EGBTextInfoBase );
  148.  
  149.         if (NULL != GfxBase)
  150.           CloseLibrary( GfxBase );
  151.  
  152.         if (NULL == string)
  153.                         exit (0);
  154.         else{
  155.                 printf ("%s.\n", string);
  156.                 exit (10);
  157.           }
  158. }
  159.  
  160.  
  161.  
  162. void main (void)
  163. {
  164.         window  = NULL;
  165.         con     = NULL;
  166.  
  167.         EGSIntuiBase =  OpenLibrary ( "egsintui.library", 0 );
  168.         if (NULL == EGSIntuiBase)
  169.           Crash ( "Could not open egsintui.library" );
  170.  
  171.         GfxBase =  OpenLibrary ( "graphics.library", 0 );
  172.         if (NULL == GfxBase)
  173.           Crash ( "Could not open gfx.library" );
  174.  
  175.         EGBBase =  OpenLibrary ( "egsgadbox.library", 0 );
  176.         if (NULL == EGBBase)
  177.           Crash ( "Could not open egsgadbox.library" );
  178.  
  179.         EGBScrollBase =  OpenLibrary ( "egb/gbscrollbox.library", 0 );
  180.         if (NULL == EGBScrollBase)
  181.           Crash ( "Could not open egb/gbscrollbox.library" );
  182.  
  183.         EGBRadioBase =  OpenLibrary ( "egb/gbradio.library", 0 );
  184.         if (NULL == EGBRadioBase)
  185.           Crash ( "Could not open egb/gbradio.library" );
  186.  
  187.         EGBSetBase =  OpenLibrary ( "egb/gbsets.library", 0 );
  188.         if (NULL == EGBSetBase)
  189.           Crash ( "Could not open egb/gbsets.library" );
  190.  
  191.         EGBSelectBase =  OpenLibrary ( "egb/gbselect.library", 0 );
  192.         if (NULL == EGBSelectBase)
  193.           Crash ( "Could not open egb/gbselect.library" );
  194.  
  195.         EGBTextInfoBase =  OpenLibrary ( "egb/gbtextinfo.library", 0 );
  196.         if (NULL == EGBTextInfoBase)
  197.           Crash ( "Could not open egb/gbtextinfo.library" );
  198.  
  199.         window = CreateGads(NULL);
  200.         if (NULL == window)
  201.           Crash ("Could not open window");
  202.  
  203.   /*
  204.   **  Handle the messages like Amiga (extend with EI_)
  205.   */
  206.  
  207.   for (;;)
  208.     {
  209.       while (NULL == (msg = (EI_EIntuiMsgPtr) GetMsg ( window->UserPort )))
  210.  
  211.       WaitPort ( window->UserPort );
  212.  
  213.       switch (msg->Class)
  214.       {
  215.  
  216.         case EI_iSIZEVERIFY:
  217.  
  218.                 printf("VerifySizing ! \n");
  219.  
  220.                 EI_RemoveGList(window,con->First,con->Num);
  221.  
  222.                 EB_DeleteGadContext(con);
  223.  
  224.          ReplyMsg ( (struct Message*)msg );
  225.          break;
  226.  
  227.         case EI_iNEWSIZE:
  228.  
  229.                 printf("Sizing ! \n");
  230.  
  231.                 EI_LockIntuition();
  232.  
  233.                 window=CreateGads(window);
  234.  
  235.                 EI_AddGList(window,con->First,con->Num);
  236.  
  237.                 EI_UnlockIntuition();
  238.  
  239.          ReplyMsg ( (struct Message*)msg );
  240.          break;
  241.  
  242.         case EI_iCLOSEWINDOW:
  243.  
  244.          ReplyMsg ( (struct Message*)msg );
  245.          Crash (NULL);
  246.          break;
  247.  
  248.         default:
  249.  
  250.          printf (" Unknown message %ld\n", msg->Class);
  251.          ReplyMsg ( (struct Message*)msg );
  252.  
  253.       }
  254.     }       /* forever */
  255.  
  256. }
  257.  
  258.